package com.yj.discovery.controller;

import com.yj.common.responses.TerminalResponse;
import com.yj.discovery.entity.DiscoveryInfo;
import com.yj.discovery.entity.DiscoveryPCInfo;
import com.yj.discovery.service.DiscoveryService;
import com.yj.inventory.entity.Inventory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Copyright 2017 (C) Yunjian-VC
 * Created on : 2017/12/13
 * Author     : Unbelievable9
 **/
@Api(tags = "易煤可视化-发现")
@Controller
@RequestMapping("/discovery")
public class DiscoveryController {

    @Autowired
    DiscoveryService discoveryService;

    @ApiOperation("获取发现内容")
    @GetMapping("/info")
    @ResponseBody
    public TerminalResponse<Object> info(@ApiParam("显示内容数量上限") @RequestParam(required = false) Integer limit) {
        TerminalResponse<Object> terminalResponse;

        try {
            DiscoveryInfo discoveryInfo = discoveryService.getInfo(limit);

            terminalResponse = new TerminalResponse<>(true, "获取发现内容成功", discoveryInfo);
        } catch (Exception e) {
            e.printStackTrace();

            terminalResponse = new TerminalResponse<>(false, "获取发现内容失败", null);
        }

        return terminalResponse;
    }

    @ApiOperation("PC发现-统计信息")
    @GetMapping("/pc-total-info")
    @ResponseBody
    public TerminalResponse<Object> pcTotalInfo() {
        TerminalResponse<Object> terminalResponse;

        try {
            DiscoveryPCInfo discoveryPCInfo = discoveryService.getPCInfo();

            terminalResponse = new TerminalResponse<>(true, "获取统计信息成功", discoveryPCInfo);
        } catch (Exception e) {
            e.printStackTrace();

            terminalResponse = new TerminalResponse<>(false, "获取统计信息失败", null);
        }

        return terminalResponse;
    }

    @ApiOperation("PC发现-运输信息")
    @GetMapping("/pc-transport-info")
    @ResponseBody
    public TerminalResponse<Object> pcTransportInfo(@ApiParam("内容上限") @RequestParam("limit") Integer limit) {
        TerminalResponse<Object> terminalResponse;

        try {
            List<Map<String, Object>> transportInfoList = discoveryService.getTransportInfo(limit);

            terminalResponse = new TerminalResponse<>(true, "获取运输信息成功", transportInfoList);
        } catch (Exception e) {
            e.printStackTrace();

            terminalResponse = new TerminalResponse<>(false, "获取运输信息失败", null);
        }

        return terminalResponse;
    }

    @ApiOperation("PC发现-库存信息")
    @GetMapping("/pc-inventory-info")
    @ResponseBody
    public TerminalResponse<Object> pcInventoryInfo(@ApiParam("内容上限") @RequestParam("limit") Integer limit) {
        TerminalResponse<Object> terminalResponse;

        try {
            List<Inventory> inventoryList = discoveryService.getPCInventoryInfo(limit);

            terminalResponse = new TerminalResponse<>(true, "获取库存信息成功", inventoryList);
        } catch (Exception e) {
            e.printStackTrace();

            terminalResponse = new TerminalResponse<>(false, "获取库存信息失败", null);
        }

        return terminalResponse;
    }
}
